<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" >

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/5.2.0/turbolinks.js" integrity="sha256-iM4Yzi/zLj/IshPWMC1IluRxTtRjMqjPGd97TZ9yYpU=" crossorigin="anonymous"></script>
  <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Cousine|Inconsolata" rel="stylesheet">
  <link rel="shortcut icon" type="image/png" href="/favicon.png">

  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/css/css/fontawesome-all.min.css">
  <link rel="stylesheet" href="/css/css/work-sans-v7.css">
  <script src="/js/main.js"></script>

  <!-- Begin Jekyll SEO tag v2.6.1 -->
<title>PY: Submit Comment Reply | Hive Developer</title>
<meta name="generator" content="Jekyll v4.0.0" />
<meta property="og:title" content="PY: Submit Comment Reply" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="How to submit a comment on a post to the Steem blockchain." />
<meta property="og:description" content="How to submit a comment on a post to the Steem blockchain." />
<link rel="canonical" href="submit_comment_reply.html" />
<meta property="og:url" content="submit_comment_reply.html" />
<meta property="og:site_name" content="Hive Developer" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2020-08-26T11:52:22-07:00" />
<script type="application/ld+json">
{"description":"How to submit a comment on a post to the Steem blockchain.","mainEntityOfPage":{"@type":"WebPage","@id":"submit_comment_reply.html"},"@type":"BlogPosting","url":"submit_comment_reply.html","headline":"PY: Submit Comment Reply","dateModified":"2020-08-26T11:52:22-07:00","datePublished":"2020-08-26T11:52:22-07:00","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->


  
</head>
<body>
<header>
  <h1>
    <button type="button" class="open-nav" id="open-nav"></button>
    <a href="/"  class="logo-link"><img src="/images/logotype_black.svg" height="40" alt="Hive Developer logo"></a>
  </h1>

  
  <form action="/search/" method="get">
    <input type="text" name="q" id="search-input" placeholder="Search">
    <input type="submit" value="Search" style="display: none;">
  </form>
  

  <div id="sidebar" class="sidebar">
	
	
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/">
		<h6 class="ctrl-nav-section title">Introduction</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/#introduction-welcome">Welcome to Hive</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/quickstart/">
		<h6 class="ctrl-nav-section title">Quickstart</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/quickstart/#quickstart-choose-library">Choose Library</a></li>
						
					
						
						<li><a href="/quickstart/#quickstart-hive-full-nodes">Hive Nodes</a></li>
						
					
						
						<li><a href="/quickstart/#quickstart-testnet">Hive Testnet</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/tutorials/">
		<h6 class="ctrl-nav-section title">Tutorials</h6>
		<ul class="cont-nav-section content">
			
				
					
						<li><a href="/tutorials/#tutorials-javascript">Javascript</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-python">Python</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-ruby">Ruby</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-recipes">Recipes</a></li>
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/services/">
		<h6 class="ctrl-nav-section title">Services</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/services/#services-hive-blog">hive.blog</a></li>
						
					
						
						<li><a href="/services/#services-hivesigner">HiveSigner</a></li>
						
					
						
						<li><a href="/services/#services-jussi">Jussi</a></li>
						
					
						
						<li><a href="/services/#services-imagehoster">ImageHoster</a></li>
						
					
						
						<li><a href="/services/#services-dhf">DHF</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/apidefinitions/">
		<h6 class="ctrl-nav-section title">Appbase API</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/apidefinitions/#apidefinitions-condenser-api">Condenser Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-bridge">Bridge</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-account-by-key-api">Account By Key Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-account-history-api">Account History Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-block-api">Block Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-database-api">Database Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-debug-node-api">Debug Node Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-follow-api">Follow Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-jsonrpc">Jsonrpc</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-market-history-api">Market History Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-network-broadcast-api">Network Broadcast Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-rc-api">Rc Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-reputation-api">Reputation Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-rewards-api">Rewards Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-tags-api">Tags Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-transaction-status-api">Transaction Status Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-witness-api">Witness Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-broadcast-ops">Broadcast Ops</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-broadcast-ops-communities">Broadcast Ops Communities</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/resources/">
		<h6 class="ctrl-nav-section title">Resources</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/resources/#resources-overview">Overview</a></li>
						
					
						
						<li><a href="/resources/#resources-client-libs">Client Libraries</a></li>
						
					
						
						<li><a href="/resources/#resources-bluepaper">Bluepaper</a></li>
						
					
						
						<li><a href="/resources/#resources-whitepaper">Whitepaper</a></li>
						
					
						
						<li><a href="/resources/#resources-tools">Tools</a></li>
						
					
						
						<li><a href="/resources/#resources-hivesigner-libs">Hivesigner Libs</a></li>
						
					
						
						<li><a href="/resources/#resources-hive-keychain">Hive Keychain</a></li>
						
					
						
						<li><a href="/resources/#resources-developeradvocate">Community & Help</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/glossary/">
		<h6 class="ctrl-nav-section title">Glossary</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/glossary/#glossary-chain-basics">Chain Basics</a></li>
						
					
						
					
						
						<li><a href="/glossary/#glossary-governance">Governance</a></li>
						
					
						
						<li><a href="/glossary/#glossary-transactions">Transactions</a></li>
						
					
						
						<li><a href="/glossary/#glossary-api">API</a></li>
						
					
						
						<li><a href="/glossary/#glossary-market">Market</a></li>
						
					
				
			
		</ul>
	</section>
	
</div>



  <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
</header>
<div class="main" id="top">
  <div class="hero">
    <h1 class="hero__h1">Hive Developer Portal </h1>
    <img class="hero__img" src="/images/honey-comb-92.png" style="position: relative; top: 10px;" />
  </div>
  <section id="tutorials-python-submit-comment-reply" class="row tutorials-python-submit-comment-reply">
	<h3>
		<a id="tutorials-python-submit-comment-reply">
			PY: Submit Comment Reply
			
		</a>
	</h3>
	
		<span class="description"><p>How to submit a comment on a post to the Steem blockchain.</p>
</span>
	

	<p><span class="fa-pull-left top-of-tutorial-repo-link"><span class="first-word">Full</span>, runnable src of <a href="https://gitlab.syncad.com/hive/devportal/-/tree/master/tutorials/python/tutorials/11_submit_comment_reply">Submit Comment Reply</a> can be downloaded as part of: <a href="https://gitlab.syncad.com/hive/devportal/-/tree/master/tutorials/python">tutorials/python</a>.</span>
<br /></p>

<p>This tutorial will explain and show you how to submit a new comment to the <code class="highlighter-rouge">Steem</code> blockchain using the <code class="highlighter-rouge">commit</code> class found within the <a href="https://github.com/steemit/steem-python">steem-python</a> library.</p>

<h2 id="intro">Intro</h2>

<p>The Steem python library has a built-in function to transmit transactions to the blockchain. We are using the <code class="highlighter-rouge">post</code> method found within the <code class="highlighter-rouge">commit</code> class in the the library. It should be noted that comments and post are both treated as a <code class="highlighter-rouge">commit.post</code> operation with the only difference being that a comment/reply has an additional parameter containing the <code class="highlighter-rouge">parent post/comment</code>. There are 11 parameters within the <code class="highlighter-rouge">post</code> method:</p>

<ol>
  <li><em>title</em> - The title of the post. This is a required parameter but comments don’t have a title so the parameter is assigned an empty string value</li>
  <li><em>body</em> - The body of the post</li>
  <li><em>author</em> - The account that you are posting from</li>
  <li><em>permlink</em> - A unique adentifier for the</li>
  <li><em>tags</em> - Between 1 and 5 key words that defines the post</li>
  <li><em>reply_idendifier</em> - Identifier of the parent post(used for comments)</li>
  <li><em>json_metadata</em> - JSON meta objec that can be attached to the post</li>
  <li><em>comment_options</em> - JSON options object that can be attached to the post to specify additional options like ‘max_payouts’, ‘allow_votes’, etc.</li>
  <li><em>community</em> - Name of the community you are posting into</li>
  <li><em>beneficiaries</em> - A list of beneficiaries for posting reward distribution.</li>
  <li><em>self_vote</em> - Upvote the post as author right after posting</li>
</ol>

<p>We will only be using the parameters titel, body, author, permlink and reply_identifier as they are all that is required for a basic comment operation. If you want to explore the other parameters further you can find more information <a href="http://steem.readthedocs.io/en/latest/core.html">HERE</a>.</p>

<p>A comment made on a post is defined as a <code class="highlighter-rouge">root comment</code>. You can also comment on someone elses (or your own) comment, in which case the <code class="highlighter-rouge">parent</code> parameters would be that of the comment, and not the original post.</p>

<h2 id="steps">Steps</h2>

<ol>
  <li><a href="#setup"><strong>App setup</strong></a> - Library install and import. Connection to Steem node</li>
  <li><a href="#input"><strong>Variable input and format</strong></a> - Input and creation of varialbes</li>
  <li><a href="#steem"><strong>Initialize steem class</strong></a> - Initialize the steem class with the relevant node and private key</li>
  <li><a href="#submit"><strong>Post submission and result</strong></a> - Committing of transaction to the blockchain</li>
</ol>

<h4 id="1-app-setup-">1. App setup <a name="setup"></a></h4>

<p>In this tutorial we use 4 packages:</p>

<ul>
  <li><code class="highlighter-rouge">random</code> and <code class="highlighter-rouge">string</code> - used to create a random string used for the <code class="highlighter-rouge">permlink</code></li>
  <li><code class="highlighter-rouge">steem</code> - steem-python library and interaction with Blockchain</li>
  <li><code class="highlighter-rouge">steembase</code> - used to connect to the testnet</li>
</ul>

<p>We import the libraries and connect to the <code class="highlighter-rouge">testnet</code>.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">string</span>
<span class="kn">import</span> <span class="nn">steembase</span>
<span class="kn">import</span> <span class="nn">steem</span>

<span class="n">steembase</span><span class="o">.</span><span class="n">chains</span><span class="o">.</span><span class="n">known_chains</span><span class="p">[</span><span class="s">'STEEM'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">'chain_id'</span><span class="p">:</span> <span class="s">'79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01673'</span><span class="p">,</span>
    <span class="s">'prefix'</span><span class="p">:</span> <span class="s">'STX'</span><span class="p">,</span> <span class="s">'steem_symbol'</span><span class="p">:</span> <span class="s">'STEEM'</span><span class="p">,</span> <span class="s">'sbd_symbol'</span><span class="p">:</span> <span class="s">'SBD'</span><span class="p">,</span> <span class="s">'vests_symbol'</span><span class="p">:</span> <span class="s">'VESTS'</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Because this tutorial alters the blockchain we have to connect to the testnet. There is a demo account available for use, <code class="highlighter-rouge">cdemo</code> with private posting key <code class="highlighter-rouge">5JEZ1EiUjFKfsKP32b15Y7jybjvHQPhnvCYZ9BW62H1LDUnMvHz</code>. You can also create your own demo account by following the instructions on the <a href="https://testnet.steem.vc/">TESTNET</a> site.</p>

<h4 id="2-variable-input-and-format">2. Variable input and format<a name="input"></a></h4>

<p>The variables are captured via a simple string input and allocated as seen below. The <code class="highlighter-rouge">wif</code> variable is the private posting key of the user making the comment. This key is required to commit the post to the blockchain.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#capture variables
</span><span class="n">parentAuthor</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Parent author: '</span><span class="p">)</span>
<span class="n">parentPermlink</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Parent permlink: '</span><span class="p">)</span>
<span class="n">author</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Username: '</span><span class="p">)</span>
<span class="n">wif</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Private posting key: '</span><span class="p">)</span>
<span class="n">body</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Comment Body: '</span><span class="p">)</span>
</code></pre></div></div>

<p>We join the two <code class="highlighter-rouge">parent</code> values and assign it to the <code class="highlighter-rouge">reply_identifier</code> parameter. We also use a random generator to create a new <code class="highlighter-rouge">permlink</code> for the post being created</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#combining parent values to create reply identifier
</span><span class="n">reply_identifier</span> <span class="o">=</span> <span class="s">'/'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">parentAuthor</span><span class="p">,</span><span class="n">parentPermlink</span><span class="p">])</span>

<span class="c1">#random generator to create post permlink
</span><span class="n">permlink</span> <span class="o">=</span> <span class="s">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">choices</span><span class="p">(</span><span class="n">string</span><span class="o">.</span><span class="n">digits</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">10</span><span class="p">))</span>
</code></pre></div></div>

<p>The random generator is limited to 10 characters in this case but the permlink can be up to 256 bytes. If the permlink value is left empty then it auto creates a permlink based on the title of the post. The permlink is unique to the author only which means that multiple authors can have the same title for thier post.</p>

<h4 id="3-initialize-steem-class">3. Initialize steem class<a name="steem"></a></h4>

<p>We initialize the steem class by connecting to the specific <code class="highlighter-rouge">testnet</code> node. We also require the <code class="highlighter-rouge">private posting key</code> of the contributing author in order to commit the post which is also specified during this operation.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#connect node and private posting key
</span><span class="n">client</span> <span class="o">=</span> <span class="n">steem</span><span class="o">.</span><span class="n">Steem</span><span class="p">(</span><span class="n">nodes</span><span class="o">=</span><span class="p">[</span><span class="s">'https://testnet.steem.vc'</span><span class="p">],</span> <span class="n">keys</span><span class="o">=</span><span class="p">[</span><span class="n">wif</span><span class="p">])</span>
</code></pre></div></div>

<h4 id="4-post-submission-and-result">4. Post submission and result<a name="submit"></a></h4>

<p>The last step is to transmit the post through to the blockchain. This is done with the <code class="highlighter-rouge">post</code> method within the <code class="highlighter-rouge">commit</code> class. All the defined parameters are submitted with the function. As stated earlier in the tutorial, there are quite a few parameters for this function but for a basic comment these 5 are all that’s required.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#commit post to blockchain
</span><span class="n">client</span><span class="o">.</span><span class="n">commit</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s">''</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">body</span><span class="p">,</span> <span class="n">author</span><span class="o">=</span><span class="n">author</span><span class="p">,</span> <span class="n">permlink</span><span class="o">=</span><span class="n">permlink</span><span class="p">,</span> <span class="n">reply_identifier</span><span class="o">=</span><span class="n">reply_identifier</span><span class="p">)</span>

<span class="k">print</span><span class="p">(</span><span class="s">"Comment created successfully"</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="n">permlink</span><span class="p">)</span>
</code></pre></div></div>

<p>A simple confirmation is printed on the screen if the comment is committed successfully. We also print the <code class="highlighter-rouge">permlink</code> for the comment on screen. This is purely for convenience to make it easier to retrieve the permlink if a new author or the same author would like to another comment on the one just made.</p>

<p>You can also check on the <a href="http://condenser.steem.vc/blog/@cdemo">testportal</a> for the comment or for a post to comment on. Alternatively you can create your own post to comment on following the <code class="highlighter-rouge">10_submit_post</code> tutorial.</p>

<h3 id="to-run-the-tutorial">To Run the tutorial</h3>

<ol>
  <li><a href="getting_started.html">review dev requirements</a></li>
  <li><code class="highlighter-rouge">git clone https://gitlab.syncad.com/hive/devportal.git</code></li>
  <li><code class="highlighter-rouge">cd devportal/tutorials/python/11_submit_comment_reply</code></li>
  <li><code class="highlighter-rouge">pip install -r requirements.txt</code></li>
  <li><code class="highlighter-rouge">python index.py</code></li>
  <li>After a few moments, you should see a prompt for input in terminal screen.</li>
</ol>

<hr />

</section>

</div>
<div class="footer">
  <a href="#">Back to top</a>
</div>
<script>
    document.getElementById("open-nav").addEventListener("click", function () {
        document.body.classList.toggle("nav-open");
    });
</script>
</body>
</html>


<script src="/js/adjust.js"></script>

